<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <script>
    function getRandom(N, M) {
      return Math.floor(Math.random() * (M - N + 1)) + N
    }
    let random = getRandom(1,10)
    // let random = Math.floor(Math.random() * 11) + 1
    while (true) {
      
      let num = +prompt('请输入1-10之间的数字')
      if (num > random) {
        alert('数字猜大了,继续猜')
      }
      else if (num < random) {
        alert('数字猜小了,继续猜')
      }
      else {
        alert('猜对了')
        break
      }
    }
  </script>
</body>
</html>